#include<stdlib.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<string.h>

int main(int argc,char **argv){

   int shmid;
   char *shmtext;
   int begin;
    shmid = shmget((key_t)0x5000,1024,0644|IPC_CREAT);
    if (shmid==-1)
    {
        perror("fail!");
        exit(0);
    }
    shmtext =(char *)shmat(shmid,NULL,0);
    //sprintf(shmtext,"写入到共享内存中 %d ",getpid());
    // char *tmp = strcat("写入到共享内存中 ",(char *)getpid());
    char *tmp = "写入到共享内存中";
    memcpy(shmtext,tmp,strlen(tmp));

    printf("写入后的值是：%s \n",shmtext);
    if(shmdt(shmtext) == 0){
        printf(" 共享内存删除成功 \n");
        
    }
    shmctl(shmid,IPC_RMID,NULL);


    



   return 0;
}